﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Deloitte.Data
{
    public class DataTableToObjectListMapper<T>
    {
        private DataRowToObjectMapper<T> _rowMapper;

        public DataRowToObjectMapper<T> RowMapper
        {
            get { return _rowMapper; }
            set { _rowMapper = value; }
        }
        public DataTableToObjectListMapper(DataRowToObjectMapper<T> rowMapper)
        {
            this.RowMapper = rowMapper;
        }
        public List<T> MapTable(DataTable2 table)
        {
            List<T> list = new List<T>();
            DataRowToObjectMapper<T> featureMapper = new DataRowToObjectMapper<T>(this.RowMapper.ColumnMaps);
            foreach (DataRow row in table.Rows)
            {
                list.Add(featureMapper.MapDataRow(row));
            }
            return list;
        }
        public bool IsValidMap(DataTable2 table)
        {
            return RowMapper.IsValidMap(table);
        }
    }
}
